package com.cg.design.graphicdesignpattern.state;

/**
 * 表示“白天”状态的类，实现了State接口
 *
 * @program: LeetCode->DayState
 * @description: 表示“白天”状态的类，实现了State接口
 * @author: cg
 * @create: 2022-04-03 11:25
 **/
public class DayState implements State {

    /**
     * 单例模式
     */
    private static final DayState SINGLETON = new DayState();

    /**
     * 禁止创建实例
     */
    private DayState() {
    }

    /**
     * 获取唯一实例
     *
     * @return
     */
    public static State getInstance() {
        return SINGLETON;
    }

    @Override
    public void doClock(Context context, int hour) {
        // 如果时间参数为晚上时间，切换为晚上状态
        if (hour < 9 || 17 <= hour) {
            context.changeState(NightState.getInstance());
        } else if (12 <= hour && hour < 13) {
            context.changeState(NoonState.getInstance());
        }
    }

    @Override
    public void doUes(Context context) {
        context.recordLog("使用金库(白天)");
    }

    @Override
    public void doAlarm(Context context) {
        context.callSecurityCenter("按下警铃(白天)");
        context.changeState(UrgentState.getInstance());
    }

    @Override
    public void doPhone(Context context) {
        context.callSecurityCenter("正常通话(白天)");
    }

    @Override
    public String toString() {
        return "[白天]";
    }
}
